package com.talent.web.config.alipay;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName：TlAlipayConfig
 * @Author: hszhou
 * @Date: 2025/3/26 13:21
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@Configuration
@RequiredArgsConstructor
public class TlAlipayConfig {


    private final AliPayProperties aliPayProperties;

    @Bean
    public AlipayClient alipayClient() throws AlipayApiException {

        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl(aliPayProperties.getHost());
        alipayConfig.setAppId(aliPayProperties.getAppId());
        alipayConfig.setPrivateKey(aliPayProperties.getAppPrivateKey());
        alipayConfig.setFormat(aliPayProperties.getFormat());
        alipayConfig.setCharset(aliPayProperties.getCharset());
        alipayConfig.setSignType(aliPayProperties.getSignType());
        alipayConfig.setAlipayPublicKey(aliPayProperties.getAlipayPublicKey());
        return new DefaultAlipayClient(alipayConfig);
    }
}
